<template>
  <div>
    <DataGrid :columns="columns" ref="grid" border :action="action">
      <template slot="easySearch">
        <Form ref="formInline" :model="easySearch" inline>
          <FormItem prop="keys">
            <Input placeholder="全名/实体名称/数据库表名" v-model="easySearch.keys.value" v-width="300" />
          </FormItem>
          <FormItem>
            <Button type="primary" @click="search">查询</Button>
          </FormItem>
        </Form>
      </template>
      <template slot="searchForm">
        <Search />
      </template>
      <template slot="buttons">
        <Button type="primary" @click="add">新增</Button>
      </template>
    </DataGrid>
    <Modal
      v-model="modal"
      :title="title"
      width="1200"
      footer-hide
      :fullscreen="modalFull"
      @on-visible-change="mclose"
    >
      <component :is="detail" :eid="curId" @on-close="cancel" @on-ok="ok" />
    </Modal>
  </div>
</template>
<script>
import Api from "./api";
import Search from "./search";
export default {
  name: "list",
  components: {
    Search,
  },
  head: {
    title: "实体定义",
    author: "henq",
    description: "DbEntityDefined  5/27/2020 10:43:31 AM",
  },
  data() {
    return {
      modalFull: true,
      action: Api.index,
      easySearch: {
        keys: { op: "dbFullName,entityName,dbTableName,tableDescription", value: null },
      },
      modal: false,
      title: "新增",
      detail: null,
      curId: null,
      columns: [
        {
          key: "tableDescription",
          title: this.l("tableDescription"),
          align: "left",
          high: true,
        },
        {
          key: "entityName",
          title: this.l("entityName"),
          align: "left",
          easy: true,
          high: true,
        },
        {
          key: "dbTableName",
          title: this.l("dbTableName"),
          align: "left",
          easy: true,
          high: true,
        },
        {
          key: "base",
          title: this.l("base"),
          align: "center",
          width:100,
          high: true,
          code: "System.DbEnityDefined.Base",
        },
        {
          key: "id",
          title: this.$t("id"),
          hide: true,
          align: "left",
          high: true,
        },
        {
          key: "dbFullName",
          title: this.l("dbFullName"),
          align: "left",
          easy: true,
          high: true,
        },
        { key: "methods", title: this.l("methods"),width:300, align: "left", high: true ,code:"System.DbEnityDefined.Methods"},
        // {
        //   key: "nameRule",
        //   title: this.l("nameRule"),
        //   align: "left",
        //   high: true,
        // },
        {
          key: "status",
          title: this.l("status"),
          align: "center",
          width:80,
          high: true,
          code: "System.DbEnityDefined.Status",
        },
        { key:"creationTime",title:this.l("creationTime")   ,align:"left",hide:true,  high:true  },
        { key:"creatorUserId",title:this.l("creatorUserId")   ,align:"left"    ,hide:true,high:true  },
        { key:"lastModificationTime",title:this.l("lastModificationTime")   ,align:"left"    ,hide:true,high:true  },
        { key:"lastModifierUserId",title:this.l("lastModifierUserId")   ,align:"left"    ,hide:true,high:true  },
        // { key:"deletionTime",title:this.l("deletionTime")   ,align:"left"    ,high:true  },
        // { key:"deleterUserId",title:this.l("deleterUserId")   ,align:"left"    ,high:true  },
        // { key:"isDeleted",title:this.l("isDeleted")   ,align:"left"    ,hide:true,high:true  },
        {
          title: "操作",
          key: "action",
          width: 400,
          align: "center",
          render: (h, params) => {
            return h("div", { class: "action" }, [
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.view(params.row.id) },
                },
                "查看"
              ),
               h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.$router.push('/bus/'+params.row.entityName) },
                },
                "数据"
              ),
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.sync(params.row.id) },
                },
                "同步"
              ),
              ,
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.mock(params.row.id) },
                },
                "Mock"
              ),
              ,
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.view(params.row.id) },
                },
                "服务"
              ),
              ,
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.view(params.row.id) },
                },
                "统计"
              ),
              ,
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.view(params.row.id) },
                },
                "Dto"
              ),
              ,
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.view(params.row.id) },
                },
                "引用"
              ),
              ,
              h(
                "op",
                {
                  attrs: { oprate: "detail" },
                  on: { click: () => this.view(params.row.id) },
                },
                "UI"
              ),
              //h('op', { attrs: { oprate: 'copy' }, on: { click: () => this.copy(params.row.id) } }, '克隆'),
              h(
                "op",
                {
                  attrs: { oprate: "edit" },
                  on: { click: () => this.edit(params.row.id) },
                },
                "编辑"
              ),
              h(
                "op",
                {
                  attrs: { oprate: "delete" },
                  on: { click: () => this.remove(params.row.id) },
                },
                "删除"
              ),
            ]);
          },
        },
      ],
    };
  },
  mounted() {
    console.log(this);
  },
  async fetch({ store, params }) {
    await store.dispatch("loadDictionary"); // 加载数据字典
  },
  methods: {
    ok() {
      this.$refs.grid.load();
      this.modal = false;
      this.curId = null;
    },
    search() {
      this.$refs.grid.reload(this.easySearch);
    },
    add() {
      this.curId = null;
      this.title = "新增";
      this.detail = () => import("./add");
      this.modal = true;      
      this.modalFull = true;
    },
    sync(id) {
      this.curId = id;
      this.title = "同步";
      this.detail = () => import("./sync");
      this.modal = true;
      this.modalFull = false;
    },
    copy(id) {
      this.curId = id;
      this.title = "克隆";
      this.detail = () => import("./add");
      this.modal = true;
    },
    view(id) {
      this.curId = id;
      this.title = "详情";
      this.detail = () => import("./detail");
      this.modal = true;
      this.modalFull = true;
    },
    edit(id) {
      this.curId = id;
      this.title = "编辑";
      this.detail = () => import("./edit");
      this.modalFull = true;
      this.modal = true;
    },
    mock(id) {
      this.curId = id;
      this.title = "Mock";
      this.detail = () => import("./mock");
      this.modalFull = true;
      this.modal = true;
    },
    remove(id) {
      Api.delete(id).then((r) => {
        if (r.success) {
          this.$refs.grid.load();
          this.$Message.success("删除成功");
        }
      });
    },
    cancel() {
      this.curId = null;
      this.modal = false;
    },
    mclose(v) {
      if (!v) {
        this.modalFull = false;
      }
    },
    l(key) {
      /*
           DbEntityDefined:{
      base:'',
      dbFullName:'全名',
      columns:'列',
      tags:'特征码',
      nameRule:'名规则',
      entityName:'实体名称',
      dbTableName:'数据库表名',
      tableDescription:'表备注',
      creationTime:'',
      creatorUserId:'',
      lastModificationTime:'',
      lastModifierUserId:'',
      deletionTime:'',
      deleterUserId:'',
      isDeleted:'',
      status:'',
           }
           */
      let vkey = "DbEntityDefined" + "." + key;
      return this.$t(vkey) || key;
    },
  },
};
</script>
<style lang="less">
</style>